package com.open.launcher.activity.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.open.launcher.R;
import com.open.launcher.base.BaseRecycleViewAdapter;
import com.open.launcher.bean.allchannels.AllChannel;


/**
 * Created by Administrator on 2018/4/8 0008
 * function:
 */

public class PlayerFirstListAdapater extends BaseRecycleViewAdapter<PlayerFirstListAdapater.ViewHolder> {
    private boolean selected;
    private AllChannel bean;

    public AllChannel getBean() {
        return bean;
    }

    public void setBean(AllChannel bean) {
        this.bean = bean;
    }

    public boolean isSelected() {
        return selected;
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
    }

    public PlayerFirstListAdapater(Context context) {
        mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_allchannels_view, null, false));
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        if (position==0){
            holder.itemView.requestFocus();
        }
        if (bean!=null){
            holder.channlType.setText(bean.getData().get(position).getName());
        }
//        holder.itemView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (listener != null) {
//                    listener.onItemClick(v, position);
//                }
//            }
//        });
        holder.itemView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean b) {
                if (focusChangelistener!=null){
                    focusChangelistener.onItemFoucus(view,b);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        if (bean!=null){
            return bean.getData().size();
        }else {
            return 0;
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView channlType;
        public ViewHolder(View itemView) {
            super(itemView);
            channlType=(TextView) itemView.findViewById(R.id.mainchanel_text);
        }
    }
}
